package com.sbc.easyexcel.handler;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;

/**
 * @description: 自定义 Excel 效果
 * @author: songbaicheng
 * @create: 2024-08-18 12:56
 **/
public class CustomHeadStyleHandler implements RowWriteHandler {

    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) {
        if (isHead) {
            Sheet sheet = writeSheetHolder.getSheet();
            CellStyle cellStyle = sheet.getWorkbook().createCellStyle();

            // 设置背景色为绿色
            cellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
            // 设置填充模式
            cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

            for (Cell cell : row) {
                cell.setCellStyle(cellStyle);
            }
        }
    }
}
